package com.testaidl;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Auth：yujunyao
 * Since: 2016/5/31 16:01
 * Email：yujunyao@yonglibao.com
 */
public class ConnectionService extends Service {
    private static final String TAG = "ConnectionService";
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return new ConnectionImp();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "onCreate");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.i(TAG, "onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy");
    }

    @Override
    public boolean onUnbind(Intent intent) {
        Log.i(TAG, "onUnbind");
        return super.onUnbind(intent);
    }

    @Override
    public void onRebind(Intent intent) {
        super.onRebind(intent);
        Log.i(TAG, "onRebind");
    }


    private class ConnectionImp extends Connection.Stub {
        private Display display;
        @Override
        public void bindData(Display display) throws RemoteException {
            this.display = display;
        }

        @Override
        public void connect() throws RemoteException {
            display.displayToast("connect");
        }

        @Override
        public void connecting() throws RemoteException {
            display.displayToast("connecting");
        }

        @Override
        public void connected() throws RemoteException {
            display.displayToast("connected");
        }
    }
}
